﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;
using System.Data;
using System.Data.SqlClient;

namespace DAO
{
    public class PhieuSuDungNVLDAO
    {
        public static List<PhieuSuDungNVLDTO> Select_Phieu_not_read_yet()
        {
            List<PhieuSuDungNVLDTO> list = new List<PhieuSuDungNVLDTO>();
            String strSql = "select MaPhieuSuDungNVL from PhieuSuDungNVL where TinhTrang=0";

            try
            {
                DataTable dt = SqlDataAccessHelper.ExcuteQuery(strSql);
                foreach (DataRow dr in dt.Rows)
                {
                    PhieuSuDungNVLDTO psd = new PhieuSuDungNVLDTO();
                    psd.MaPhieuSuDungNVL = int.Parse(dr["MaPhieuSuDungNVL"].ToString());
                    list.Add(psd);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return list;
        }

        public static bool Update_TinhTrang(string MaPhieuSuDungNVL,int TinhTrang)
        {
            bool result = false;

            string strSQLEmployee = "Update PhieuSuDungNVL set TinhTrang=@TinhTrang where MaPhieuSuDungNVL=@ID";

            try
            {
                // Create List Sql Parameter
                List<SqlParameter> sqlParams = new List<SqlParameter>();
                sqlParams.Add(new SqlParameter("@ID", MaPhieuSuDungNVL));
                sqlParams.Add(new SqlParameter("@TinhTrang", TinhTrang));
                // Call Store Procedure
                int n = SqlDataAccessHelper.ExcuteNoneQuery(strSQLEmployee, sqlParams);
                if (n == 1)
                    result = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return result;
        }
    }
}
